package com.by.service.impl;

import com.by.bean.WareHousing;
import com.by.common.crud.BaseServiceImpl;
import com.by.mapper.WareHousingMapper;
import com.by.query.WareHousingQuery;
import com.by.service.WareHousingService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Service
public class WareHousingServiceImpl extends BaseServiceImpl<WareHousing, WareHousingMapper> implements WareHousingService {


    public int save(WareHousing entity) {
        //生成部门编码
        entity.setCode(generateDeptCode());
        return super.save(entity);
    }

    @Override
    public int delete(Serializable id) {
        int n = baseMapper.delete(id);
        return super.delete(id);
    }


    @Override
    public int updateStatus(int id, int status) {
        return baseMapper.updateStatus(id, status);
    }


    String generateDeptCode() {
        //id查询最大编码
        String maxCode = baseMapper.queryMaxCode();
        if (null == maxCode) {
                return "101";
        }
        //如果存在最大编码  101
        Integer tmp = Integer.parseInt(maxCode);
        tmp++;
        return String.valueOf(tmp);
    }

    @Override
    public List<Map> getWareHousingList() {
        return baseMapper.getWareHousingList();
    }

}
